找传奇、传世资源到传世资源站!

C# 推箱子游戏源码(带音效/关卡)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

Vs2010 FrameWork 4.0 具有音效 选择关卡 前一关后一关 时间排行榜等功能。
from clipboard
from clipboard TimeSelect
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Xml;namespace MyGame{ public partial class TimeSelect : Form { public TimeSelect() { InitializeComponent(); } private void TimeSelect_Load(object sender, EventArgs e) { XMLOperation xmloperation = new XMLOperation(); //打开一个xml文件, XmlDocument doc = new XmlDocument(); doc.Load(Environment.CurrentDirectory.ToString() "/time.xml"); if (!xmloperation.xmlgetnode("one")) { //遍历controlone下的标签,找到name和time标签的内容。 XmlNodeList nol1 = doc.SelectNodes("/controls/controlone"); foreach (XmlNode no in nol1) { //将取出的姓名和所用时间赋给窗体上的标签显示 label_name1.Text = no.SelectSingleNode("name").InnerText; label_time1.Text = no.SelectSingleNode("time").InnerText; } } if (!xmloperation.xmlgetnode("two")) { //遍历controltwo下的标签,找到name和time标签的内容。 XmlNodeList nol2 = doc.SelectNodes("/controls/controltwo"); foreach (XmlNode no in nol2) { //将取出的姓名和所用时间赋给窗体上的标签显示 label_name2.Text = no.SelectSingleNode("name").InnerText; label_time2.Text = no.SelectSingleNode("time").InnerText; } } if (!xmloperation.xmlgetnode("three")) { //遍历controlthree下的标签,找到name和time标签的内容。 XmlNodeList nol3 = doc.SelectNodes("/controls/controlthree"); foreach (XmlNode no in nol3) { //将取出的姓名和所用时间赋给窗体上的标签显示 label_name3.Text = no.SelectSingleNode("name").InnerText; label_time3.Text = no.SelectSingleNode("time").InnerText; } } } }}MainForm:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Media;using Microsoft.VisualBasic;using System.IO;using System.Collections;namespace MyGame{ public partial class MainForm : Form { Config con = new Config(); SoundPlayer ap = new SoundPlayer("1.wav"); SoundPlayer ap1 = new SoundPlayer("2.wav"); SoundPlayer ap2 = new SoundPlayer("3.wav"); public int time = 1000; public MainForm() { InitializeComponent(); } int[,] data; ucItem[,] items; Point curPoint; int stage = 0; int step = 0; private void Form1_Load(object sender, EventArgs e) { 开ToolStripMenuItem.Checked = true; 开ToolStripMenuItem.Enabled = false; ap.PlayLooping(); toolStripMenuItem1.Enabled = false; 第一关ToolStripMenuItem.Enabled = false; 上一关ToolStripMenuItem1.Enabled = stage > 0; 下一关ToolStripMenuItem1.Enabled = stage < Config.Levels.Length - 1; //Controls.Clear(); toolStripStatusLabel4.Text = string.Format("{0:000}", stage 1); step=0; toolStripStatusLabel6.Text = string.Format("{0:000}", step); //定义一个16x16的数组存放数据 data = new int[16, 16]; //定义一个16X16的用户控件数组存放对应图片 if(items==null) items = new ucItem[16, 16]; string[] lvl = Config.Levels[stage].Split(",".ToCharArray()); for (int i = 0; i < lvl.Length; i ) { string tmp = lvl[i]; for (int j = 0; j < tmp.Length; j ) { ucItem item=null; if (items[i, j] == null) { item = new ucItem(); items[i, j] = item; } else { item = items[i, j]; } data[i, j] = int.Parse(tmp[j].ToString());item.Tag = data[i, j].ToString(); item.OldValue = data[i, j]; item.Left = j * item.Width 5; item.Top = i* item.Height 5; this.Controls.Add(item); item.RefImage(); if (data[i, j] >= 6)//上 下 左 右 { curPoint = new Point(); curPoint.Y = i; curPoint.X = j; } } } ShowInfo(); } private void ShowInfo() { toolStripStatusLabel8.Text = curPoint.X "," curPoint.Y; } private void GoNewPoint(Point newPoint1,Point newPoint2) { toolStripStatusLabel6.Text = string.Format("{0:000}", step); ////默认初始值为false //bool isFinshed=false; if(newPoint1.X<0||newPoint1.Y<0) return; int n1 = data[newPoint1.Y, newPoint1.X]; int n2 = data[newPoint2.Y, newPoint2.X]; if (n1 <= 1)//空白 墙 { return; } if (n1 == 2||n1==3)// 地板||空洞 { step = step 1; //地板或者空洞的坐标 等于 人物的坐标 data[newPoint1.Y, newPoint1.X] = data[curPoint.Y, curPoint.X]; //刷新地板||空洞的图片 RefImg(newPoint1); data[curPoint.Y, curPoint.X] = items[curPoint.Y, curPoint.X].OldValue; //刷新人物的上 下 左 右 RefImg(curPoint); curPoint = newPoint1; return; } if (n1 == 4)//入洞 { if (n2 == 2 || n2 == 3)//地板||空洞 { if (n2 == 2)//地板 { step = step 1; data[newPoint2.Y, newPoint2.X] = 5;//球 } if (n2 == 3)//空洞 { step = step 1; data[newPoint2.Y, newPoint2.X] = 4;//入洞 } RefImg(newPoint2); data[newPoint1.Y, newPoint1.X] = data[curPoint.Y, curPoint.X]; RefImg(newPoint1); data[curPoint.Y, curPoint.X] = items[curPoint.Y, curPoint.X].OldValue; RefImg(curPoint); curPoint = newPoint1; CheckFinshed(); } } if (n1 == 5)//球 { if (n2 == 1 || n2 == 5)//墙||球 { return; } if (n2 == 2)//地板 { step = step 1; data[newPoint2.Y, newPoint2.X] = 5;//球 } if (n2 == 3)//空洞 { step = step 1; data[newPoint2.Y, newPoint2.X] = 4;//入洞 //isFinshed = true; } RefImg(newPoint2); data[newPoint1.Y, newPoint1.X] = data[curPoint.Y, curPoint.X]; RefImg(newPoint1); data[curPoint.Y, curPoint.X] = items[curPoint.Y, curPoint.X].OldValue; RefImg(curPoint); curPoint = newPoint1; CheckFinshed(); } } //编写一个刷新图片的方法 void RefImg(Point p) { items[p.Y, p.X].Tag = data[p.Y, p.X]; items[p.Y, p.X].RefImage(); } private void CheckFinshed() { if (stage == 0) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第一关"); stage ; Form1_Load(null, null); } if (stage == 1) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第二关"); stage ; Form1_Load(null, null); } if (stage == 2) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第三关"); stage ; Form1_Load(null, null); } if (stage == 3) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第四关"); stage ; Form1_Load(null, null); } if (stage == 4) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第五关"); stage ; Form1_Load(null, null); } if (stage == 5) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第六关"); stage ; Form1_Load(null, null); } if (stage == 6) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第七关"); stage ; Form1_Load(null, null); } if (stage == 7) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第八关"); stage ; Form1_Load(null, null); } if (stage == 8) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } MessageBox.Show("恭喜通过第九关"); stage ; Form1_Load(null, null); } if (stage == 9) { for (int i = 0; i < items.GetUpperBound(0); i ) { for (int j = 0; j < items.GetUpperBound(1); j ) { if (data[i, j] == 5) { return; } } } timer1.Stop(); MessageBox.Show("抵达终点,恭喜您!!"); if (con.istime(1000 - time)) { //将计时排行的窗体打开显示当前排行 TimeSelect timeselect = new TimeSelect(); timeselect.ShowDialog(); } KeyPreview = false; stage = 0; Form1_Load(null, null); time = 1000; toolStripStatusLabel2.Text = "---"; 第一关ToolStripMenuItem.Enabled = false; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } } private void 退出游戏ToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } private void timer1_Tick(object sender, EventArgs e) { if (time > 0) { //当时间在一秒一秒减少,在toolStripStatusLabel1显示出来 time--; toolStripStatusLabel2.Text = time.ToString(); } else if (time == 0) { //将计时器停止,弹出消息"您用时超过60秒,下次加油吧!!"。 timer1.Stop(); MessageBox.Show("您用时超出,下次加油吧!"); time = 1000; stage = 0; Form1_Load(null, null); KeyPreview = false; toolStripStatusLabel2.Text = "---"; 选择关卡ToolStripMenuItem.Enabled = true; } } private void 上一关ToolStripMenuItem1_Click(object sender, EventArgs e) { if (stage > 0) { stage--; Form1_Load(null, null); } if (toolStripStatusLabel4.Text == "001") { 第一关ToolStripMenuItem.Enabled = false; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "002") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = false; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "003") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = false; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "004") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = false; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "005") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = false; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "006") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = false; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "007") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = false; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "008") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = false; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "009") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = false; 第十关ToolStripMenuItem.Enabled = true; } } private void 下一关ToolStripMenuItem1_Click(object sender, EventArgs e) { if (stage < Config.Levels.Length) { stage ; Form1_Load(null, null); } if (toolStripStatusLabel4.Text == "005") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = false; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "002") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = false; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "003") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = false; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "004") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = false; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "006") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = false; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "007") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = false; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "008") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = false; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "009") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = false; 第十关ToolStripMenuItem.Enabled = true; } if (toolStripStatusLabel4.Text == "010") { 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = false; } } private void 重玩本关ToolStripMenuItem1_Click(object sender, EventArgs e) { Form1_Load(null, null); 上一关ToolStripMenuItem1.Enabled = false; 下一关ToolStripMenuItem1.Enabled = false; step = 0; } private void 暂停游戏ToolStripMenuItem_Click(object sender, EventArgs e) { if (开始游戏ToolStripMenuItem1.Enabled == true) { MessageBox.Show("还没开始游戏呢"); } else { timer1.Stop(); KeyPreview = false; 开始游戏ToolStripMenuItem1.Enabled = true; 暂停游戏ToolStripMenuItem.Enabled = false; } } private void 时间排行榜ToolStripMenuItem_Click(object sender, EventArgs e) { //将计时排行的窗体打开显示当前排行 TimeSelect timeselect = new TimeSelect(); timeselect.Show(); } private void 关ToolStripMenuItem_Click(object sender, EventArgs e) { toolStripMenuItem1.Enabled = true; toolStripMenuItem2.Enabled = true; 关ToolStripMenuItem.Checked = true; 开ToolStripMenuItem.Checked = false; 开ToolStripMenuItem.Enabled = true; 关ToolStripMenuItem.Enabled = false; ap.Stop(); } private void toolStripMenuItem2_Click_1(object sender, EventArgs e) { ap1.PlayLooping(); toolStripMenuItem1.Enabled = true; toolStripMenuItem2.Enabled = false; } private void toolStripMenuItem1_Click(object sender, EventArgs e) { ap.PlayLooping(); toolStripMenuItem1.Enabled = false; toolStripMenuItem2.Enabled = true; } private void 开始游戏ToolStripMenuItem1_Click(object sender, EventArgs e) { 开始游戏ToolStripMenuItem1.Enabled = false; 暂停游戏ToolStripMenuItem.Enabled = true; 上一关ToolStripMenuItem1.Enabled = false; 下一关ToolStripMenuItem1.Enabled = false; timer1.Interval = 1000; timer1.Start(); KeyPreview = true; 选择关卡ToolStripMenuItem.Enabled = false; } private void 文件ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 第一关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 0; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = false; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第二关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 1; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = false; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第三关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 2; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = false; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第四关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 3; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = false; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第五关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 4; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = false; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第六关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 5; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = false; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第七关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 6; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = false; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第八关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 7; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = false; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; } private void 第九关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 8; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = false; 第十关ToolStripMenuItem.Enabled = true; } private void 第十关ToolStripMenuItem_Click(object sender, EventArgs e) { stage = 9; Form1_Load(null, null); 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = false; } private void 新游戏ToolStripMenuItem_Click(object sender, EventArgs e) { time = 1000; timer1.Stop(); stage = 0; Form1_Load(null, null); 暂停游戏ToolStripMenuItem.Enabled = true; 选择关卡ToolStripMenuItem.Enabled = true; 开始游戏ToolStripMenuItem1.Enabled = true; 第一关ToolStripMenuItem.Enabled = true; 第二关ToolStripMenuItem.Enabled = true; 第三关ToolStripMenuItem.Enabled = true; 第四关ToolStripMenuItem.Enabled = true; 第五关ToolStripMenuItem.Enabled = true; 第六关ToolStripMenuItem.Enabled = true; 第七关ToolStripMenuItem.Enabled = true; 第八关ToolStripMenuItem.Enabled = true; 第九关ToolStripMenuItem.Enabled = true; 第十关ToolStripMenuItem.Enabled = true; toolStripStatusLabel2.Text = "---"; } //覆盖默认的系统键处理方式,遇到方向键,则直接返回,系统不处理,这样键值就会被传递到窗体,触发KeyDown事件 protected override bool ProcessDialogKey(Keys keyData) { if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right) return false; else return base.ProcessDialogKey(keyData); } private void MainForm_KeyDown(object sender, KeyEventArgs e) { Point newPoint1 = curPoint; Point newPoint2 = curPoint; switch (e.KeyCode) { case Keys.Up: newPoint1.Y--; newPoint2.Y -= 2; data[curPoint.Y, curPoint.X] = 6; GoNewPoint(newPoint1, newPoint2); break; case Keys.Down: newPoint1.Y ; newPoint2.Y = 2; data[curPoint.Y, curPoint.X] = 7; GoNewPoint(newPoint1, newPoint2); break; case Keys.Left: newPoint1.X--; newPoint2.X -= 2; data[curPoint.Y, curPoint.X] = 8; GoNewPoint(newPoint1, newPoint2); break; case Keys.Right: newPoint1.X ; newPoint2.X = 2; data[curPoint.Y, curPoint.X] = 9; GoNewPoint(newPoint1, newPoint2); break; } //switch (e.KeyValue) //{ // case 38://上 // newPoint1.Y--; // newPoint2.Y -= 2; // data[curPoint.Y, curPoint.X] = 6; // GoNewPoint(newPoint1, newPoint2); // break; // case 40://下 // newPoint1.Y ; // newPoint2.Y = 2; // data[curPoint.Y, curPoint.X] = 7; // GoNewPoint(newPoint1, newPoint2); // break; // case 37://左 // newPoint1.X--; // newPoint2.X -= 2; // data[curPoint.Y, curPoint.X] = 8; // GoNewPoint(newPoint1, newPoint2); // break; // case 39://右 // newPoint1.X ; // newPoint2.X = 2; // data[curPoint.Y, curPoint.X] = 9; // GoNewPoint(newPoint1, newPoint2); // break; // case 27://Esc // Application.Exit(); // break; //} ShowInfo(); } private void 音乐ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 开ToolStripMenuItem_Click(object sender, EventArgs e) { 开ToolStripMenuItem.Checked = true; 关ToolStripMenuItem.Checked = false; 开ToolStripMenuItem.Enabled = false; 关ToolStripMenuItem.Enabled = true; ap.PlayLooping(); toolStripMenuItem1.Enabled = false; toolStripMenuItem2.Enabled = true; } private void 显示信息ToolStripMenuItem_Click(object sender, EventArgs e) { information infor = new information(); infor.ShowDialog(); } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复